package com.pb.news.util;

import lombok.Data;

/**
 * Page--BDQN_WEB_NEWS
 *
 * @author: Jovi
 * @createTime: 2018-04-09 11:23
 **/
@Data
public class Page {

    /* 总页数 */
    private int totalPageCount = 1;

    /* 每页显示数 */
    private int pageSize = 0;

    /* 总量 */
    private int recordCount = 0;

    /* 当前页号 */
    private int currPageNo = 1;

    public int getCurrPageNo() {
        if (totalPageCount == 0) {
            return 0;
        }
        return currPageNo;
    }

    public void setRecordCount(int recordCount) {

        if (recordCount > 0) {
            this.recordCount = recordCount;
            this.setTotalPageCountByRs();
        }
    }

    /* 设置总页数 */
    private void setTotalPageCountByRs() {

        if (this.recordCount % this.pageSize == 0) {
            this.totalPageCount = this.recordCount / this.pageSize;
        } else if (this.recordCount % this.pageSize >= 0) {
            this.totalPageCount = this.recordCount / this.pageSize + 1;
        } else {
            this.totalPageCount = 0;
        }
    }

    public int getStartRow() {
        return (currPageNo - 1) * pageSize + 1;
    }

    public int getEndRow() {
        return currPageNo * pageSize;
    }


}
